using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Drawing;using Emgu.CV;using Emgu.CV.CvEnum;using Emgu.CV.UI;using Emgu.CV.Structure;using Emgu.CV.Util;namespace test1{ class Program { static void Main(string[] args) { VideoCapture cap = new VideoCapture("test7.mp4"); if (cap.IsOpened) { int i = 0; Mat frame = new Mat(); while (true) { cap.Read(frame);//读取一帧 if (!frame.IsEmpty) { i ; string imgPath = "./" i.ToString() ".bmp"; CvInvoke.Imwrite(imgPath, frame); Image<Bgr, Byte> image = new Image<Bgr, byte>(imgPath); #region use MCvObjectDetection.Rect MCvObjectDetection[] regions; using (HOGDescriptor des = new HOGDescriptor()) { des.SetSVMDetector(HOGDescriptor.GetDefaultPeopleDetector()); regions = des.DetectMultiScale(image); } foreach (MCvObjectDetection pedestrain in regions) image.Draw(pedestrain.Rect, new Bgr(Color.Lime), 2); CvInvoke.Imshow("image", image); #endregion if (CvInvoke.WaitKey(10) == 27)//esc退出 { break; } } else { Console.WriteLine("帧为空"); break; } } } else { Console.WriteLine("视频打开错误"); return; } } }}
评论